/*
 * Copyright (c) 2025 CAX Conversion Project
 */
package com.comac.ins.isfd.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.idempotent.annotation.RepeatSubmit;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.bo.IsfdDatasourceConfigurationBo;
import com.comac.ins.isfd.domain.bo.IsfdDatasourceConfigurationQueryBo;
import com.comac.ins.isfd.domain.vo.IsfdDatasourceConfigurationVo;
import com.comac.ins.isfd.domain.vo.IsfdDatasourceTestVo;
import com.comac.ins.isfd.service.IIsfdDatasourceConfigurationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 数据源数据集成-数据源配置
 *
 * @author Lion Li
 * @date 2024-10-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/datasourceConfiguration")
public class IsfdDatasourceConfigurationController extends BaseController {

    private final IIsfdDatasourceConfigurationService isfdDatasourceConfigurationService;

    /**
     * 查询数据源配置列表
     */
    @SaCheckPermission("isfd:datasourceConfiguration:list")
    @PostMapping("/list")
    public TableDataInfo<IsfdDatasourceConfigurationVo> list(@RequestBody IsfdDatasourceConfigurationQueryBo bo) {
        return isfdDatasourceConfigurationService.queryPageList(bo);
    }



    /**
     * 获取数据源配置详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("isfd:datasourceConfiguration:query")
    @GetMapping("/{id}")
    public R<IsfdDatasourceConfigurationVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(isfdDatasourceConfigurationService.queryById(id));
    }

    /**
     * 新增数据源配置
     */
    @SaCheckPermission("isfd:datasourceConfiguration:add")
    //@Log(title = "数据源配置", businessType = BusinessType.INSERT)
    //@RepeatSubmit()
    @PostMapping(value="/add")
    @Operation(summary = "新增数据源配置",security=@SecurityRequirement(name="isfd:datasourceConfiguration:add"))
    public R<Void> parameterConfigAnalysisAdd(@RequestBody IsfdDatasourceConfigurationBo isfdDatasourceConfigurationBo) {
        return toAjax(isfdDatasourceConfigurationService.insertByBo(isfdDatasourceConfigurationBo));
    }

    /**
     * 修改数据源配置
     */
    @SaCheckPermission("isfd:datasourceConfiguration:edit")
    @Log(title = "数据源配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping(value="/edit")
    @Operation(summary = "修改数据源配置",security=@SecurityRequirement(name="isfd:datasourceConfiguration:edit"))
    public R<Void> edit(@RequestBody IsfdDatasourceConfigurationBo bo) {
        return toAjax(isfdDatasourceConfigurationService.updateByBo(bo));
    }

    /**
     * 删除数据源配置
     *
     * @param ids 主键串
     */
    @SaCheckPermission("isfd:datasourceConfiguration:remove")
    @Log(title = "数据源配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(isfdDatasourceConfigurationService.deleteWithValidByIds(List.of(ids)));
    }

    /**
     * 测试数据源配置
     */
    @SaCheckPermission("isfd:datasourceConfiguration:test")
    @RepeatSubmit()
    @PostMapping(value="/test")
    @Operation(summary = "测试数据源配置",security=@SecurityRequirement(name="isfd:datasourceConfiguration:test"))
    public R<IsfdDatasourceTestVo> test(@RequestBody IsfdDatasourceConfigurationBo bo) {
        IsfdDatasourceTestVo isfdDatasourceTestVo = new IsfdDatasourceTestVo();
        isfdDatasourceTestVo.setResult(isfdDatasourceConfigurationService.testByBo(bo));
        return R.ok(isfdDatasourceTestVo);
    }


}
